#ifndef _PATIENTDATA_
#define _PATIENTDATA_

#include "sqlite3.h"
#include <vector>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>

class Instance
{
public:
    Instance(std::string sopuid, std::string seriesuid, boost::filesystem::path filename, std::string sopclassuid, std::string transfersyntax)
        : sopuid(sopuid), seriesuid(seriesuid), filename(filename), sopclassuid(sopclassuid), transfersyntax(transfersyntax) {}
    std::string sopuid;
    std::string seriesuid;
    boost::filesystem::path filename;
    std::string sopclassuid;
    std::string transfersyntax;
};

class Series
{
public:
    Series(std::string seriesuid, std::string studyuid, std::string seriesdesc)
        : seriesuid(seriesuid), studyuid(studyuid), seriesdesc(seriesdesc) {}
    std::string seriesuid;
    std::string studyuid;
    std::string seriesdesc;
};

class Study
{
public:
    Study() {}
    Study(std::string studyuid, std::string patid, std::string patname, std::string studydesc, std::string studydate, bool checked)
        : studyuid(studyuid), patid(patid), patname(patname), studydesc(studydesc), studydate(studydate), checked(checked) {}
    std::string studyuid;
    std::string patid;
    std::string patname;
    std::string studydesc;
    std::string studydate;
    bool checked;
};

class Patient
{
public:
    Patient(std::string patid, std::string name, std::string birthday)
        : patid(patid), name(name), birthday(birthday) {};
    std::string patid;
    std::string name;
    std::string birthday;
};

class PatientData
{
public:

    PatientData();
    ~PatientData();
    void createdb();
    void Clear();
    bool Load(boost::filesystem::path filename);
    bool Save(boost::filesystem::path filename);
    int AddPatient(std::string patid, std::string patname, std::string birthday);
    void GetPatients(boost::function< int(Patient &) > action);
    // void GetPatients(std::vector<Patient> &patients);
    int AddStudy(std::string studyuid, std::string patid, std::string patname, std::string studydesc, std::string studydate);
    void GetStudies(boost::function< int(Study &) > action);
    void GetStudies(std::string patientid, std::string patientname, boost::function< int(Study &) > action);
    void SetStudyCheck(std::string studyuid, bool checked);
    // void GetStudies(std::vector<Study> &studies);
    int AddSeries(std::string seriesuid, std::string studyuid, std::string seriesdesc);    
    void GetSeries(std::string studyuid, boost::function< int(Series &) > action);
    // void GetSeries(std::vector<Series> &series);
    int AddInstance(std::string sopuid, std::string seriesuid, boost::filesystem::path filename, std::string sopclassuid, std::string transfersyntax);
    void GetInstances(std::string seriesuid, boost::function< int(Instance &) > action);
    // void GetInstances(std::vector<Instance> &instances);

protected:    
    sqlite3 *db;

};


#endif